home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 693 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.2 KB

  1. Path: chronicle.mti.sgi.com!austern
  2. From: phalpern@truffle.ultranet.com (Pablo Halpern)
  3. Newsgroups: comp.std.c++
  4. Subject: Re: no operator bool()?
  5. Date: 12 Mar 1996 20:22:20 PST
  6. Organization: UltraNet Communications, Inc.
  7. Approved: austern@isolde.mti.sgi.com
  8. Message-ID: <31445809.5921189@news.ultranet.com>
  9. References: <313ddfd9.16044605@sqarc.sq.com> <313E19BB.5AE2E407@cantrip.org>
  10. NNTP-Posting-Host: isolde.mti.sgi.com
  11. X-Original-Date: Mon, 11 Mar 1996 17:30:52 GMT
  12. X-Newsreader: Forte Agent .99d/16.182
  13. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  14.     iQBVAwUBMUZNiEy4NqrwXLNJAQGd5wH/fQ331WXkTYEqEV/Ts8dCaB+reT+tQmqm
  15.     m4R+3D0C810MaS7lrFTnAojtbECkeJf/DsRHmGRlJs94+4hf1AFrYw==
  16.     =Gd/M
  17. Originator: austern@isolde.mti.sgi.com
  18.  
  19. "Nathan Myers, http://www.cantrip.org/" <ncm@cantrip.org> wrote:
  20.  
  21. >Automatic conversions can be a problem in general, but the problems 
  22. >with automatic conversions to a numeric type are ridiculous.  
  23. >Compatibility with C has its downside. 
  24. >
  25. >As a side note...  The problem with automatic conversions is not
  26. >only that the conversion may be called unexpectedly; the 
  27. >possibility of the conversion affects overloading, so it may 
  28. >force you to add "unnecessary" casts to guide the compiler to 
  29. >the correct choice of function to call.
  30.  
  31. Sounds like another reason to permit the keyword "explicit" to apply to
  32. conversion operators. I really don't see why the committee is so
  33. resistant to this concept. I think the following would be a perfectly
  34. satisfactory usage:
  35.  
  36.    class istream : public ...
  37.    {
  38.      ...
  39.      explicit operator bool() const;
  40.      ...
  41.    };
  42.  
  43.    void f()
  44.    {
  45.      while (bool(cin))
  46.        // do something
  47.    }
  48.  
  49. Its clear. Its easy to remember. Its clean. Same would work for
  50. auto_ptr<>.
  51.  
  52. -------------------------------------------------------------
  53. Pablo Halpern                   phalpern@truffle.ultranet.com
  54.  
  55. I am self-employed. Therefore, my opinions *do* represent 
  56. those of my employer.
  57. ---
  58. [ comp.std.c++ is moderated.  To submit articles: Try just posting with your 
  59.                 newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  60.   comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  61.   Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  62.   Comments? mailto:std-c++-request@ncar.ucar.edu 
  63. ]
  64.